# include <bits/stdc++.h>
using namespace std;

struct node {
    int sum;
    node *ls, *rs;
    bool lz;
    node() {
        sum = 0;
        lz = 0;
        ls = rs = NULL;
    }
} *root;
# define mid ((l + r) >> 1)

node *build(int l, int r) {
    node *x = new node();
    if(l == r) {
        return x;
    } else {
        x->ls = build(l, mid);
        x->rs = build(mid + 1, r);
        return x;
    }
}

void change(node *x, int l, int r, int s, int t) {
    if(x->lz) {
        if(x->ls) x->ls->lz = 1;
        if(x->rs) x->rs->lz = 1;
        if(x->ls) x->ls->sum = mid - l + 1 - x->ls->sum;
        if(x->rs) x->rs->sum = r - mid - x->rs->sum;
        x->lz = 0;
    }
    if(l == s && r == t) {
        x->lz = 1;
        x->sum = r - l + 1 - x->sum;
    } else {
        if(t <= mid) change(x->ls, l, mid, s, t);
        else if(s > mid) change(x->rs, mid + 1, r, s, t);
        else change(x->ls, l, mid, s, mid),
             change(x->rs, mid + 1, r, mid + 1, t);
        x->sum = x->ls->sum + x->rs->sum;
    }
}

int query(node *x, int l, int r, int s, int t) {
    if(x->lz) {
        if(x->ls) x->ls->lz = 1;
        if(x->rs)x->rs->lz = 1;
        if(x->ls)x->ls->sum = mid - l + 1 - x->ls->sum;
        if(x->rs)x->rs->sum = r - mid - x->rs->sum;
        x->lz = 0;
    }
    if(l == s && r == t) {
        return x->sum;
    } else {
        if(t <= mid) return query(x->ls, l, mid, s, t);
        else if(s > mid) return query(x->rs, mid + 1, r, s, t);
        else return query(x->ls, l, mid, s, mid) + query(x->rs, mid + 1, r, mid + 1, t);
    }
}

int n, m;

int main() {
    freopen("in", "r", stdin);
    scanf("%d %d", &n, &m);
    root = build(1, n);
    for(int i = 1; i <= m; i++) {
        int op, l, r;
        scanf("%d %d %d", &op, &l, &r);
        if(!op) {
            change(root, 1, n, l, r);
        } else {
            printf("%d\n", query(root, 1, n, l, r));
        }
    }
}
